package sasl

// Client->Server: Start authenticating using Mechanism.
// If the mechanism is client-first and the protocol supports it, use
// the provided FirstResponse.
type MsgStart struct {
	Mechanism     string
	FirstResponse []byte
}

// Server->Client: Give the correct answer to this challenge.
type MsgChallenge []byte

// Client->Server: Here's the answer to your last challenge.
type MsgResponse []byte

// Client->Server: I give up on this auth mechanism.
type MsgClientCancel struct{}

// Server->Client: Understood, waiting next MsgStart.
type MsgClientCancelAck struct{}

// TODO: S->C cancellation. It's much less common than
// client-initiated cancellation, and mucks up the state machine a
// little.

// Server->Client: Authentication succeeded with current mechanism.
type MsgSuccess []byte

// Server->Client: Authentication failed with current mechanism.
type MsgFailure []byte

// Client->Server: SASL exchange complete.
// While some protocols explicitly tell the server when to end the
// SASL exchange, this message is mostly to inform the client that the
// SASL exchange is done.
type MsgDone struct {
	Success bool
	Data    []byte
}

func (m MsgDone) Error() string {
	if m.Success {
		return "No error"
	}
	return string(m.Data)
}
